{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "WARNING:tensorflow:From D:\\anaconda3\\lib\\site-packages\\tensorflow\\python\\compat\\v2_compat.py:96: disable_resource_variables (from tensorflow.python.ops.variable_scope) is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "non-resource variables are not supported in the long term\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "import tensorflow.compat.v1 as tf\n",
    "tf.disable_v2_behavior()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "from PIL import Image\n",
    "import time\n",
    "from ChessBoard import ChessBoard\n",
    "import matplotlib.pyplot as plt\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "def printChess(chess):\n",
    "    print(\"  \",end=\"\")\n",
    "    for i in range(15):\n",
    "        print(\"%3d\" %(i), end=\"\")\n",
    "    print(\"\")\n",
    "\n",
    "    for i in range(15):\n",
    "        print(\"%2d\" %(i), end=\"\")\n",
    "        for j in range(15):\n",
    "            if chess[i, j] == 0:\n",
    "                print(\"  *\", end=\"\")\n",
    "            elif chess[i, j] == 1:\n",
    "                print(\"  o\", end=\"\")\n",
    "            else:\n",
    "                print(\"  -\", end=\"\")\n",
    "        print(\"\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "board = ChessBoard()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "# AI函数\n",
    "def solve(board,ai):\n",
    "    if board.turn == ChessBoard.BLACK:\n",
    "        max = -9999999\n",
    "        pair = [-1,-1]\n",
    "        val = 0\n",
    "        #遍历每一个格点\n",
    "        for i in range(0,15):\n",
    "            for j in range(0,15):\n",
    "                if board.board[i][j] == ChessBoard.EMPTY:#这个点是空的\n",
    "                    with graph[ai].as_default():\n",
    "                        val = sess[ai].run(y[ai],feed_dict={xs[ai]:board.board.reshape(1,15*15)})\n",
    "                    if val>max:\n",
    "                        max = val\n",
    "                        pair = [i,j]\n",
    "    else:\n",
    "        min = 9999999\n",
    "        pair = [-1,-1]\n",
    "        val = 0\n",
    "        for i in range(0,15):\n",
    "            for j in range(0,15):\n",
    "                if board.board[i][j]== ChessBoard.EMPTY:#这个点是空的\n",
    "                    with graph[ai].as_default():\n",
    "                        val = sess[ai].run(y[ai],feed_dict={xs[ai]:board.board.reshape(1,15*15)})\n",
    "                    if val<min:\n",
    "                        min = val\n",
    "                        pair = [i,j]\n",
    "    return pair,val[0,0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
